<?php
/**
 * Created by 无所谓已
 * User: Administrator
 * Date: 2025-08-17
 * Time: 0:50
 */

namespace plugin\csauto\app\service\site;


use plugin\csauto\app\model\TorrentListModel;

class RssService
{
    private static $torrentKey = array(
//        'torrents_title' => 'torrentsTitle',
        'torrents_audio_code' => 'torrentsAudioCode',
        'torrents_code' => 'torrentsCode',
        'torrents_resolution' => 'torrentsResolution',
        'torrents_production_team' => 'torrentsProductionTeam',
        'torrents_size' => 'torrentsSize',
        'torrents_view' => 'torrentsInfo',
        'torrents_hash' => 'torrentsHash',
        'torrents_type' => 'torrentsType',
        'torrents_medium' => 'torrentsMedium',
        'torrent_small_descr' => 'subtitle',
        'torrents_tag' => 'tags'

    );

    public static function addTorrent($item, $siteCookie, $data = array())
    {
        $dataKey = array();
        $model = new TorrentListModel;

        $model->site_id = $item['site_id'];
        $model->torrent_id = $item['id'];
        $model->torrent_url = $item['url'];
        $model->torrent_title = $item['title'];
        if (isset($data['tags'])) {
            if (in_array('禁转', $data) || in_array('限转', $data)) {
                echo "禁转/限转资源" . PHP_EOL;
                $model->torrents_status = 99;
                $model->save();
                return false;
            }
        }
        foreach (RssService::$torrentKey as $key => $value) {
            if (!isset($data[$value]) && $key != "torrents_hash") {
                echo "view 缺少 {$value} " . isset($data->$value) . PHP_EOL;
                print_r($data);
                return false;
            }
            if ($value == 'tags') {
                $model->$key = json_encode($data[$value]);
            } else {
                if (empty($data[$value]) || !$data[$value]) {
                    $model->$key = null;
                } else {
                    $model->$key = $data[$value];
                }
            }
        }
        /*对种子大小进行检测*/
        /*完成数据整合，开始入库操作*/
        return $model->save();
//        return true;
    }


}